<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <title>酒店注册页面</title>
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/hotel.css"/>
    <script type="text/javascript" src="layer/layer.js"></script>
</head>
<body class="regist-body">
<input type="hidden" id="UserStatusid" th:value="${session.UserStatusid}"/>
<script type="text/javascript">
    var ustatusid = $('#UserStatusid').val();
    if(ustatusid == 1){
        window.location.href = "toDecode.do";
    }
</script>
<form action="" method="post">
    <div class="regist">
        <div class="regist-text">
            <ul>
                <li><label for="userAccount">账号:</label></li>
                <li><label for="userPassword">密码:</label></li>
                <li>类型:</li>
                <li>提问:</li>
                <li><label for="userAnswer">答案:</label></li>
            </ul>
        </div>
        <div class="regist-input">
            <ul>
                <li><input type="text" id="userAccount"/></li>
                <li><input type="password" id="userPassword"/></li>
                <li>
                    <select id="selectType">
                        <option value="管理员">管理员</option>
                        <option value="经理">经理</option>
                    </select>
                </li>
                <li>
                    <select id="selectHobby">
                        <option value="爱好">爱好</option>
                        <option value="学历">学历</option>
                        <option value="食物">食物</option>
                        <option value="年龄">年龄</option>
                        <option value="职业">职业</option>
                    </select>
                </li>
                <li><input type="text" id="userAnswer"/></li>
            </ul>
        </div>
    </div>
    <div class="btnregist">
        <button class="btn-regist" id="btn-regist" type="button">注册</button>
        <button class="regist-cancel" type="reset">取消</button>
    </div>
</form>
<div class="back-login">
    返回<a href="toLogin.do">登录</a>
</div>
</body>
<script type="text/javascript">
    $('#userAccount').blur(checkUser);
    $('#userPassword').blur(checkPassword);
    $('#userAnswer').blur(checkAnswer);
    var userAccount;
    var userPassword;
    var userAnswer;
    function checkUser() {
        userAccount = $('#userAccount').val();
        var reg_userAccount = /^\w{6,10}$/;
        var flag = reg_userAccount.test(userAccount);
        if (flag) {
            $("#userAccount").css("border", "");
        } else {
            layer.tips('账号需满足6到10位', '#userAccount');
            $("#userAccount").css("border", "1px solid red");
        }
        return flag;
    }
    function checkPassword() {
        userPassword = $('#userPassword').val();
        var reg_userPassword = /^\w{6,10}$/;
        var flag = reg_userPassword.test(userPassword);
        if (flag) {
            $("#userPassword").css("border", "");
        } else {
            layer.tips('密码需满足6到10位', '#userPassword');
            $("#userPassword").css("border", "1px solid red");
        }
        return flag;
    }
    function checkAnswer() {
        userAnswer = $('#userAnswer').val();
        var flag = (userAnswer != '');
        if (flag) {
            $("#userAnswer").css("border", "");
        } else {
            layer.tips('答案不能为空', '#userAnswer');
            $("#userAnswer").css("border", "1px solid red");
        }
        return flag;
    }
    var selectType;
    selectType = $('#selectType').val();
    $(function () {
        $('#selectType').change(function (){
            selectType = $('#selectType').val();
        });
    });
    var selectHobby;
    selectHobby = $('#selectHobby').val();
    $(function () {
        $('#selectHobby').change(function (){
            selectHobby = $('#selectHobby').val();
        });
    });
    $('#btn-regist').click(function (){
        if(checkUser()&&checkPassword()&&checkAnswer()){
            $.post(
                "regist.do",
                {"userAccount":userAccount,"userPassword":userPassword,"userAnswer":userAnswer,"selectType":selectType,"selectHobby":selectHobby},
                function (data){
                    if (data.status == 0) {
                        window.location.href = "toIndex.do";
                    } else if (data.status == 1) {
                        layer.msg(data.message);
                    }
                }
            );
        }else {
            layer.msg('请检查信息是否正确');
        }
    })
</script>
</html>
